//
//  LHTabBar.swift
//  weibao
//
//  Created by 李浩 on 16/4/5.
//  Copyright © 2016年 李浩. All rights reserved.
//

import UIKit

class LHTabBar: UITabBar {

    
    
    
    
    override init(frame: CGRect) {
        
        
        super.init(frame: frame)
        
        
        SetLoadUi()
        
    }

    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

    
    
    func SetLoadUi(){


    
        addSubview(composeBtn)
        
    
    
    
    }
    
    
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        
        var index = 0
        
        //设置 x,y ,w,h
        
        let width = self.bounds.width/5
        
        let height = self.bounds.height
        
        for subview in subviews {
        
        
            //判断一下子视图是不是 UITabBarButton
        
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
            
    //改变子视图的frame
            
            subview.frame = CGRectMake(CGFloat(index) * width, 0, width, height)
            
            
            index++
                
                if index==2{
                    index++
                
                    composeBtn.frame=CGRectMake(2 * width, 0, width, height)
                
                }
                
                
            }
        
        }

        
        
        
    }
    
    
    lazy var composeBtn :UIButton = {
    
        let button = UIButton(type: UIButtonType.Custom)
    
        
        //设置

    
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
    
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        
        
        return button
    
    
    }()
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

}
